<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/12/6
 * Time: 10:46
 */

//1.判断是否为空
if (empty($_POST['userName']))
{
    echo '手机/邮箱/个人空间地址为空';
    die;
}
if (empty($_POST['passWord']))
{
    echo '密码为空';
    die;
}

$userName = $_POST['userName'];
$passWord = $_POST['passWord'];

//打印userName 和 passWord
//print_r($_POST);

//2.登入成功，则设置一个cookies,名字：Token,值md5(用户名+密码+时间戳),效期：24小时
if ($userName=='admin' && $passWord=='123456')
{
    echo '<h1>登陆成功！！！</h1>';
    $md5=md5($userName.$passWord.time());
    setcookie('Token',$md5,time()+24*3600);
    echo $_COOKIE['Token'];

//    判断Cookie是否存在
    if(!empty($_COOKIE['Token'])){
        echo 'cookie存在！！！<br />';
        echo '你的cookies名字为'.$_COOKIE['Token'];
        echo '<br />';

?><!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
</head>
<body>
<form action="picture.php" method="post" enctype="multipart/form-data">
            请选择商品图片
    <input type="file"  name="file" id="file" multiple="multiple"  >
    <br />
    <img src="" id="showImg">
    <input type="submit" id="" value="提交" />
</form>
<!--    <button onclick="showImg();">显示图片</button>-->
</body>


<script type="text/javascript">
    var fileObj = document.getElementById('file');
    function showImg() {

        var files = fileObj['files'];
        var URL = window.URL || window.webkitURL;
        var imgURL = URL.createObjectURL(files[0]);
        document.getElementById('showImg').src = imgURL;
    }
    onload = function(){
        console.log(fileObj)
        fileObj.onchange = showImg;
    }
</script>
</html>
<?
}else {
        echo '手机/邮箱/个人空间地址或密码错误';
    }
}
?>

